//
//@File    :	7.8_arrfun4.cpp
//@Time    :	2021/08/14 11:28:44
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	functions with an array range
//

#include <iostream>
const int ArSize =8;
using namespace std;
int sum_arr(const int * begin,const int * end);
int main()
{
    int cookies[ArSize] = {1,2,4,8,16,32,64,128};

    int sum=sum_arr(cookies,cookies+ArSize);
    cout<<"Total cookies esten: "<<sum<<endl;
    sum=sum_arr(cookies,cookies+3);
    cout<<"First three esters ate "<<sum<<" cookies.\n";
    sum=sum_arr(cookies+4,cookies+8);
    cout<<"Last four esters ate "<<sum<<" cookies.\n";
    
    system("pause");
    return 0;
}

int sum_arr(const int *begin,const int * end)
{
    const int *pt;
    int total=0;

    for (pt = begin;pt!=end;pt++)
    {
        total=total+*pt;
    }
    return total;
}
